//
//  NickNameViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/14.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "NickNameViewController.h"

@interface NickNameViewController ()<UITextFieldDelegate>
{
    UITextField *nameField;
}
@end

@implementation NickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    
}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.navigationItem.title = @"修改昵称";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(saveName)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50*displaywidth)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, SCREEN_WIDTH-30*displaywidth, 40*displaywidth) placeholder:@"请输入昵称" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
    [textfield setValue:RGB(179, 179, 179) forKeyPath:@"_placeholderLabel.textColor"];
    textfield.text = _nickName;
    textfield.textColor = RGB(77, 77, 77);
    textfield.delegate = self;
    textfield.clearButtonMode = UITextFieldViewModeAlways;
    [backView addSubview:textfield];
    nameField = textfield;
}

- (void)saveName
{
    if ([nameField.text isEqualToString:@""])
    {
        [LTools showMBProgressWithText:@"请输入昵称" addToView:self.view];
        return;
    }
    WEAKSELF;
    NSDictionary *dic = @{@"nickname":nameField.text};
    [HYBaseHandler requestUpdateInfoParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"修改成功" addToView:sharedDelegate.window];
             [weakSelf.navigationController popViewControllerAnimated:YES];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
